﻿<%@ Page Language="C#" MasterPageFile="~/Theme/Stander/Stander.master" AutoEventWireup="true" CodeFile="Bill.aspx.cs" Inherits="Bill_Bill" %>
<%@ Import Namespace="Active.Core" %>
<%@ Register Src="../User Controls/BillInfoControl.ascx" TagName="BillInfoControl"
    TagPrefix="uc1" %>
<asp:Content ID="Content1" ContentPlaceHolderID="ContentPlaceHolder1" Runat="Server">
<asp:MultiView ID="MultiView1" runat="server" ActiveViewIndex="0">
<asp:View ID="MainView" runat="server">
<uc1:BillInfoControl id="BillInfoControl1" runat="server"></uc1:BillInfoControl>
<p><asp:LinkButton ID="lbtnEditBill" runat="server" OnClick="lbtnEditBill_Click">编辑清单</asp:LinkButton></p>
<h2>所包含的订单列表</h2>
<asp:GridView ID="OrdersGridView" DataKeyNames="Id" runat="server" CssClass="normal mouseOver"
    DataSourceID="OrdersDataSource" AutoGenerateColumns="False" OnRowCommand="OrdersGridView_RowCommand">
    <Columns>
        <asp:HyperLinkField DataNavigateUrlFields="Id" DataNavigateUrlFormatString="~/Bill/CustomerOrders.aspx?id={0}"
            Text="客户订单" />
        <asp:HyperLinkField DataNavigateUrlFields="Id" DataNavigateUrlFormatString="~/Bill/MediaOrders.aspx?id={0}"
            Text="媒介订单" />
        <asp:BoundField HeaderText="订单号" DataField="Number" />
        <asp:TemplateField HeaderText="播放版本" SortExpression="PlayVersons">
            <ItemTemplate>
                <%# Formater.PlayVersions(Eval("PlayVersions") as string[]) %>
            </ItemTemplate>
        </asp:TemplateField>
        <asp:HyperLinkField DataNavigateUrlFields="MediaId"
            DataNavigateUrlFormatString="~/Media/Media.aspx?id={0}"
            DataTextField="MediaName" HeaderText="媒介"/>
        <asp:TemplateField HeaderText="广告周期">
            <ItemTemplate>
                <asp:Label runat="server" Text='<%# Eval("StartDate", "{0:yyyy-M-d}") +"~"+ Eval("EndDate", "{0:yyyy-M-d}") %>'></asp:Label>
            </ItemTemplate>
        </asp:TemplateField>
        <asp:TemplateField ShowHeader="False">
            <ItemTemplate>
                <asp:LinkButton ID="lbtnDelete" runat="server" OnClientClick="return deleteConfirm(event);" CausesValidation="False" CommandName="Delete"
                    Text="删除"></asp:LinkButton>
            </ItemTemplate>
        </asp:TemplateField>
    </Columns>
    <EmptyDataTemplate>
        暂无订单信息.
    </EmptyDataTemplate>
</asp:GridView>
<csla:CslaDataSource ID="OrdersDataSource" runat="server" 
    TypeName="Active.Core.Orders, Active.Core"
    TypeSupportsPaging="False" TypeSupportsSorting="False" 
    OnSelectObject="OrdersDataSource_SelectObject" OnDeleteObject="OrdersDataSource_DeleteObject">
</csla:CslaDataSource>
<p>
    <asp:LinkButton ID="lbtnAddOrder" runat="server" OnClick="lbtnAddOrder_Click">添加订单</asp:LinkButton>
</p>
</asp:View>
<asp:View ID="EditBillView" runat="server">
<p>
    <asp:LinkButton ID="lbtnReturn" runat="server" OnClick="lbtnReturn_Click" >返 回</asp:LinkButton>
</p>
<h2>填写清单信息</h2>
<asp:UpdatePanel ID="UpdatePanel1" runat="server" ChildrenAsTriggers="true" UpdateMode="Conditional">
<ContentTemplate>
<div class="AspNet-DetailsView">
    <ul>
    <li>
    <asp:Label id="lblAgent" runat="server" AssociatedControlID="txtAgentName">代理:</asp:Label> 
    <asp:TextBox ID="txtAgentName" runat="server" ></asp:TextBox>
    <ajaxToolkit:AutoCompleteExtender runat="server" ID="AutoCompleteExtender2" 
         TargetControlID="txtAgentName" ServiceMethod="GetAgentNamesList"
         ServicePath="~/WebServies/AutoCompleteService.asmx" MinimumPrefixLength="0" 
         CompletionInterval="500" EnableCaching="true" Enabled="true"
         CompletionSetCount="10"/>
    </li>
    <li>
    <asp:Label id="lblCustomer" runat="server" AssociatedControlID="txtCustomerName">客户:</asp:Label> 
    <asp:TextBox ID="txtCustomerName" runat="server" AutoPostBack="true" 
        OnTextChanged="txtCustomerName_TextChanged"></asp:TextBox>
    <asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server" ControlToValidate="txtCustomerName"
        ErrorMessage="请选择客户" ValidationGroup="Bill"></asp:RequiredFieldValidator>
    <ajaxToolkit:AutoCompleteExtender runat="server" ID="AutoCompleteExtender3"
         TargetControlID="txtCustomerName" ServiceMethod="GetCustomerNamesList"
         ServicePath="~/WebServies/AutoCompleteService.asmx" MinimumPrefixLength="0" 
         CompletionInterval="500" EnableCaching="true" Enabled="true"
         CompletionSetCount="10"/>
    </li>
    <li>
    <asp:Label id="Label5" runat="server" 
        AssociatedControlID="ddlProducts">产品:</asp:Label>
    <asp:DropDownList id="ddlProducts" runat="server" 
        DataTextField="Name" DataValueField="Id" 
        AutoPostBack="True"></asp:DropDownList>
    </li>
    <li>
    <asp:Label id="Label6" runat="server" 
        AssociatedControlID="txtStartDate">开始日期:</asp:Label> 
    <asp:TextBox id="txtStartDate" runat="server" CssClass="field date"></asp:TextBox>
    <asp:RequiredFieldValidator ID="RequiredFieldValidator2" runat="server" ControlToValidate="txtStartDate"
        ErrorMessage="请输入日期" ValidationGroup="Bill"></asp:RequiredFieldValidator>
    <asp:CompareValidator id="cpvStartDate" runat="server" ValidationGroup="Bill" 
        ErrorMessage="日期格式不对" ControlToValidate="txtStartDate" Type="Date" 
        Operator="DataTypeCheck"></asp:CompareValidator> 
    <ajaxToolkit:CalendarExtender id="txtStartDateCalendarExtender" runat="server" 
        TargetControlID="txtStartDate" Format="yyyy-M-d">
    </ajaxToolkit:CalendarExtender>
    </li>
    <li><span class="error">
        <asp:Literal ID="ErrorMessage" runat="server"></asp:Literal></span>
    </li>
    <li>
    <asp:Button id="btnCreateBill" CssClass="button" runat="server" Text="创建清单" 
        ValidationGroup="Bill" OnClick="btnCreateBill_Click">
    </asp:Button>
    <asp:Button id="btnEditBill" CssClass="button" runat="server" Text="更新清单"
        ValidationGroup="Bill" OnClick="btnEditBill_Click">
    </asp:Button> 
    </li>
    </ul>
</div>
</ContentTemplate>
<Triggers>
<asp:PostBackTrigger ControlID="btnEditBill" />
</Triggers>
</asp:UpdatePanel>
</asp:View>
<asp:View ID="AddOrderView" runat="server">
<p>
    <asp:LinkButton ID="lbtnReturnFromAddOrderView" runat="server" OnClick="lbtnReturn_Click" >返 回</asp:LinkButton>
</p>
<h2>填写订单信息</h2>
<asp:DetailsView ID="OrderDetailsView" DataKeyNames="Id" runat="server"
    DefaultMode="Insert" DataSourceID="OrderDataSource" 
    AutoGenerateRows="False" OnItemInserting="OrderDetailsView_ItemInserting">
    <Fields>
        <asp:TemplateField HeaderText="订单号:">
            <InsertItemTemplate>
                <asp:TextBox ID="txtNumber" runat="server" ValidationGroup="Order" Text='<%# Bind("Number") %>'></asp:TextBox>
            </InsertItemTemplate>
        </asp:TemplateField>
        <asp:TemplateField HeaderText="媒介:">
            <InsertItemTemplate>
                <asp:TextBox ID="txtMediaName" runat="server" ValidationGroup="Order" Text='<%# Bind("MediaName") %>'></asp:TextBox>
                <asp:RequiredFieldValidator ID="MediaNameRequiredFieldValidator" runat="server" ControlToValidate="txtMediaName"
                        ErrorMessage="请输入媒介名称" SetFocusOnError="True" ValidationGroup="Order"></asp:RequiredFieldValidator>
                <ajaxToolkit:AutoCompleteExtender runat="server" ID="aceMediaNames" 
                             TargetControlID="txtMediaName" ServiceMethod="GetMediaNamesList"
                             ServicePath="~/WebServies/AutoCompleteService.asmx" MinimumPrefixLength="0" 
                             CompletionInterval="500" EnableCaching="true" Enabled="true"
                             CompletionSetCount="10"/>
            </InsertItemTemplate>
        </asp:TemplateField>
        <asp:TemplateField HeaderText="播出版本:">
            <InsertItemTemplate>
                <asp:CheckBoxList ID="PlayVersonsCheckBoxList" CssClass="checkBoxList"
                    RepeatDirection="Horizontal" RepeatLayout="Flow" runat="server">
                </asp:CheckBoxList>
            </InsertItemTemplate>
        </asp:TemplateField>
        <asp:TemplateField>
            <InsertItemTemplate>
                <asp:Label CssClass="error" ID="SaveOrderErrorMessage" runat="server" ></asp:Label>
            </InsertItemTemplate>
        </asp:TemplateField>
        <asp:CommandField ShowEditButton="true" ShowInsertButton="true" ValidationGroup="Order" EditText="保存"
            ShowCancelButton="false" InsertText="添加" ButtonType="Button" />
    </Fields>
</asp:DetailsView>
<csla:CslaDataSource ID="OrderDataSource" runat="server" 
    TypeName="Active.Core.Order, Active.Core"
    OnInsertObject="OrderDataSource_InsertObject"
    TypeSupportsPaging="False" TypeSupportsSorting="False" OnUpdateObject="OrderDataSource_UpdateObject" OnSelectObject="OrderDataSource_SelectObject">
</csla:CslaDataSource>
</asp:View>
<asp:View ID="EditOrderView" runat="server">
<p>
    <asp:LinkButton ID="LinkButton1" runat="server" OnClick="lbtnReturn_Click" >返 回</asp:LinkButton>
</p>
<h2>更新订单信息</h2>
<asp:DetailsView ID="dvEditOrder" DataKeyNames="Id" runat="server"
    DefaultMode="Edit" DataSourceID="OrderDataSource" OnItemUpdating="OrderDetailsView_ItemUpdating"
    AutoGenerateRows="False">
    <Fields>
        <asp:TemplateField HeaderText="订单号:">
            <EditItemTemplate>
                <asp:TextBox ID="txtNumber" runat="server" ValidationGroup="Order" Text='<%# Bind("Number") %>'></asp:TextBox>
            </EditItemTemplate>
        </asp:TemplateField>
        <asp:TemplateField HeaderText="媒介:">
            <EditItemTemplate>
                <asp:TextBox ID="txtMediaName" runat="server" ValidationGroup="Order" Text='<%# Bind("MediaName") %>'></asp:TextBox>
                <asp:RequiredFieldValidator ID="MediaNameRequiredFieldValidator" runat="server" ControlToValidate="txtMediaName"
                        ErrorMessage="请输入媒介名称" SetFocusOnError="True" ValidationGroup="Order"></asp:RequiredFieldValidator>
                <ajaxToolkit:AutoCompleteExtender runat="server" ID="aceMediaNames" 
                             TargetControlID="txtMediaName" ServiceMethod="GetMediaNamesList"
                             ServicePath="~/WebServies/AutoCompleteService.asmx" MinimumPrefixLength="0" 
                             CompletionInterval="500" EnableCaching="true" Enabled="true"
                             CompletionSetCount="10"/>
            </EditItemTemplate>
        </asp:TemplateField>
        <asp:TemplateField HeaderText="播出版本:">
            <EditItemTemplate>
                <asp:CheckBoxList ID="PlayVersonsCheckBoxList" CssClass="checkBoxList"
                    RepeatDirection="Horizontal" RepeatLayout="Flow" runat="server">
                </asp:CheckBoxList>
            </EditItemTemplate>
        </asp:TemplateField>
        <asp:TemplateField>
            <EditItemTemplate>
                <asp:Label CssClass="error" ID="SaveOrderErrorMessage" runat="server" ></asp:Label>
            </EditItemTemplate>
        </asp:TemplateField>
        <asp:CommandField ShowEditButton="true" ShowInsertButton="false" ValidationGroup="Order" EditText="保存"
            ShowCancelButton="false" ButtonType="Button" />
    </Fields>
</asp:DetailsView>
</asp:View>
</asp:MultiView>
</asp:Content>

